package com.lyluly.coursemgmt.webmodule.controller;

import com.lyluly.coursemgmt.servicemodule.iService.IWechatPushService;
import com.lyluly.coursemgmt.servicemodule.model.WechatPush;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @version v1.0
 * @author clc
 */
@Controller
@RequestMapping("/wechatPushes")
public class WechatPushController {
    @Autowired
    private IWechatPushService iWechatPushService;

    /**
     * 增加一条微信推送记录
     * @param wechatPush 微信推送记录实体类
     * @param response
     */
    @PostMapping
    public void addWechatPush(@RequestBody WechatPush wechatPush, HttpServletResponse response) {
        iWechatPushService.addWechatPush(wechatPush);
    }

    /**
     * 根据记录ID修改一条微信推送记录
     * @param wechatPush 微信推送记录实体类
     * @param response
     */
    @PutMapping
    public void modifyWechatPush(@RequestBody WechatPush wechatPush, HttpServletResponse response) {
        iWechatPushService.modifyWechatPush(wechatPush);
    }

    /**
     * 根据推送ID删除一条微信推送记录
     * @param pushId 微信推送记录ID
     * @param response
     */
    @DeleteMapping("/{pushId}")
    public void removeWechatPush(@PathVariable int pushId, HttpServletResponse response) {
        iWechatPushService.removeWechatPush(pushId);
    }

    /**
     * 根据推送ID查找一条微信推送记录
     * @param pushId 微信推送记录ID
     * @return 返回相应微信推送记录
     */
    @GetMapping("/pushId/{pushId}")
    @ResponseBody
    public WechatPush findWechatPushById(@PathVariable int pushId) {
        return iWechatPushService.findWechatPushById(pushId);
    }

    /**
     * 查找所有微信推送记录
     * @return 返回所有微信推送记录
     */
    @GetMapping
    @ResponseBody
    public List<WechatPush> findWechatPushList() {
        return iWechatPushService.findWechatPushList();
    }

    /**
     * 根据班级查找若干条微信推送记录
     * @param clazz 班级
     * @return 返回相应微信推送记录
     */
    @GetMapping("/clazz/{clazz}")
    @ResponseBody
    public List<WechatPush> findWechatPushListByPushClass(@PathVariable String clazz) {
        return iWechatPushService.findWechatPushListByPushClass(clazz);
    }
}
